<style lang="scss" scoped>
</style>
<template>
    <view>
        <view class="input-box">
            <view class="input-item">
                <view class="input-label">手机号</view>
				<view class="input-body">
					<input v-model="phone" maxlength="11" type="number" placeholder="请输入手机号" class="input" >
				</view>
            </view>
            <view class="input-item">
				<view class="input-label">密码</view>
				<view class="input-body">
					<input v-model="password" type="text" :password="isHidePassword?true:false" style="margin-right: 50upx;" placeholder="请输入密码" maxlength="20"  class="input" />
					<image @click="isHidePasswordClick" class="eye" :src="isHidePassword?'/static/img/attention.png':'/static/img/attention_forbid.png'"></image>
				</view>
            </view>
            <view class="select">
                <navigator url="/pages/login/register" hover-class="none">注册</navigator>
                <navigator url="/pages/login/forget-pwd" hover-class="none">忘记密码？</navigator>
            </view>
        </view>
        <button class="button" @click="submit">登录</button>
    </view>
</template>
<script>
	import {checkPhone,checkPwd} from "@/utils/common.js"
	import util from '../../utils/util.js'
	
	export default {
		data() {
			return {
				isHidePassword:true,
				phone:"",
				password:"",
				code:""
			};
		},
		onLoad() {
			const token = uni.getStorageSync('usertoken');
			if (token) {
				console.log(token);
			} else {
				return;
			}
			var data = {
				'usertoken':token
			};
			console.log('appautologin');
			util.post('horseman/appautologin',data,(res) => {
				if (res.status == 1){
//					console.log('appautologin ok');
					uni.switchTab({
						url: '/pages/order/order'
					});
				}
			});
		},
		methods: {
			isHidePasswordClick(){
				this.isHidePassword=!this.isHidePassword
			},
			submit() {
				if(!checkPhone(this.phone)){
					return;
				};
				if(!checkPwd(this.password)){
					return;
				};
				/*
				* 登录逻辑
				*/
				var data = {
					account:this.phone,
					tel:this.phone,
					passwd: this.password,
					vCode:this.code,
				};
				console.log(data);
				util.post('horseman/login',data,(res) => {
					if (res.status == 1){
						uni.setStorageSync('usertoken',res.usertoken);
						uni.switchTab({
							url: '/pages/order/order'
						});
					}else{
						uni.showModal({
						    title: '提示',
						    content: '请检查手机号和密码',
						});
					}
				})
				/*
				* 登录逻辑
				*/
				// this.$store.commit('update',['isLogin',true]);
				// uni.reLaunch({
				// 	url:'/pages/index/index'
				// })
			}
		}
	}
</script>
